home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / Everything / ModalStuff.cp < prev    next >
Encoding:
Text File  |  1998-09-06  |  2.8 KB  |  133 lines  |  [TEXT/CWIE]

  1. // ModalStuff.cp -- Modal dialog
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <TextEdit.h>
  11. #include <Appearance.h>
  12.  
  13. #include "ResourceDefs.h"
  14. #include "Miscellany.h"
  15. #include "ControlUtils.h"
  16.  
  17. #include "ModalStuff.h"
  18.  
  19. #define kOKButton        1
  20. #define kToolsPalette        2
  21. #define kPopupsBox        3
  22. #define kFromValuesList2Popup        4
  23. #define kFromMenuPopup        5
  24. #define kListsBox        6
  25. #define kTextListList        7
  26.  
  27.  
  28. //----------
  29. // static
  30. Boolean        CModalStuff::GetModalStuff (
  31.     DModalStuffData*        ioData)
  32. {
  33.     Boolean            result = false;
  34.     CModalStuff*        dialog = new CModalStuff;
  35.  
  36.     result = dialog->RunModal (DLOG_ModalStuff, ioData);
  37.  
  38.     delete dialog;
  39.  
  40.     return result;
  41. }
  42.  
  43. //----------
  44. CModalStuff::CModalStuff ()
  45. {
  46.     mData = nil;
  47. }
  48.  
  49. //----------
  50. CModalStuff::~CModalStuff ()
  51. {
  52. }
  53.  
  54. //----------
  55. void    CModalStuff::FinishMake ()
  56. {
  57.     mOKHandle = GetControlItem (kOKButton);
  58.     SetDefaultState (mOKHandle, true);
  59.     ::SetDialogDefaultItem (mDialog, kOKButton);
  60.     mToolsHandle = GetControlItem (kToolsPalette);
  61.     mPopupsHandle = GetControlItem (kPopupsBox);
  62.     mFromValuesList2Handle = GetControlItem (kFromValuesList2Popup);
  63.     mFromMenuHandle = GetControlItem (kFromMenuPopup);
  64.     mListsHandle = GetControlItem (kListsBox);
  65.     mTextListHandle = GetControlItem (kTextListList);
  66.     BuildTextListList (mTextListHandle);
  67. }
  68.  
  69. //----------
  70. void    CModalStuff::ConnectToData (
  71.     AMSignaler*        inData)
  72. {
  73.     AMDialog::ConnectToData (inData);
  74.     mData = (DModalStuffData*) inData;
  75.  
  76.     SetControlValue (mToolsHandle, mData->GetTools2 ());
  77.     SetControlValue (mFromValuesList2Handle, mData->GetFromValuesList3 ());
  78.     SetControlValue (mFromMenuHandle, mData->GetFromMenu2 ());
  79.     SetListBoxChoice (mTextListHandle, mData->GetTextList2 ());
  80. }
  81.  
  82. //----------
  83. void    CModalStuff::DataChanged (
  84.     long        inDataID)
  85. {
  86.     if (inDataID == idTools2) {
  87.         SetControlValue (mToolsHandle, mData->GetTools2 ());
  88.     }
  89.     if (inDataID == idFromValuesList3) {
  90.         SetControlValue (mFromValuesList2Handle, mData->GetFromValuesList3 ());
  91.     }
  92.     if (inDataID == idFromMenu2) {
  93.         SetControlValue (mFromMenuHandle, mData->GetFromMenu2 ());
  94.     }
  95. }
  96.  
  97. //----------
  98. void    CModalStuff::BuildTextListList (
  99.     ControlHandle        inControl)
  100. {
  101.     ListHandle        list = GetListHandle (inControl);
  102.  
  103.     AddToList ("\pOne",   list);
  104.     AddToList ("\pTwo",   list);
  105.     AddToList ("\pThree", list);
  106.     AddToList ("\pInfinity",  list);
  107. }
  108.  
  109.  
  110. //----------
  111. void    CModalStuff::DoItem (
  112.     SInt16        inItemHit)
  113. {
  114.     switch (inItemHit) {
  115.     case kOKButton:
  116.             SetResult (true);
  117.         break;
  118.     case kToolsPalette:
  119.             mData->SetTools2 (GetControlValue (mToolsHandle));
  120.         break;
  121.     case kFromValuesList2Popup:
  122.             mData->SetFromValuesList3 (GetControlValue (mFromValuesList2Handle));
  123.         break;
  124.     case kFromMenuPopup:
  125.             mData->SetFromMenu2 (GetControlValue (mFromMenuHandle));
  126.         break;
  127.     case kTextListList:
  128.             mData->SetTextList2 (GetListBoxChoice (mTextListHandle));
  129.         break;
  130.  
  131.     } // switch
  132. }
  133.